$(document).ready(function(){
	$.ajax({
		type:"GET",
		url:baseURL+"/api/roleGroup/listAll",
		typeData:"json",
		success:function(result){
			if(result.flag==true){
				$.each(result.results,function(i,n){
					$("#role_status").append("<option value='"+result.results[i].id+"'>"+result.results[i].groupName+"</option>");
				})
			}else layer.msg('数据错误！');
			
		},
		error:function(error){
			layer.msg(error.message);
		}
	})
	$("#form-add").Validform({
		tiptype : 2,
		showAllError:true,
		datatype: {
              "empty": /^\s*$/,
              "code":/^[a-z0-9A-Z_-]{2,16}$/
              },
		callback : function(form) {
			layer.confirm('您确认提交数据嘛？',function(){
				submit();
			})
			return false;
		}
	});
	if(isManagerPlat=='true'){
		$('#roleGroup').show();
	}else $('#roleGroup').hide();
});
submit = function () {
    var data = {};
    data.name = $('#role_name').val();
    data.code = $('#role_code').val();
    data.descn = $('#role_descn').val();
    if(isManagerPlat=='true'){
    	data.roleGroupId = $('#role_status').val();
	    if (data.roleGroupId == null || data.roleGroupId == "") {
	        layer.msg("角色组不能为空！")
	        return false;
	    }
	}
    $.ajax({
        type: "post",
        url: baseURL + '/api/role/saveOrUpdateRole',
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify(data),
        success: function (result) {
            if (!result.flag) {
                layer.msg("新增失败！原因：" + result.message);
                return;
            }
            parent.location.reload();
        }
    });
}